package com.hmyd.hmyd_android.ui;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.hmyd.hmyd_android.R;
import com.hmyd.hmyd_android.AppBasic;
import com.hmyd.hmyd_android.fragment.InvestmentTypeFragment;
import com.hmyd.hmyd_android.view.ViewPagerIndicator;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;

/**
 * 投资列表
 * @author Administrator
 *
 */
@ContentView(R.layout.activity_investment_list)
public class InvestmentListActivity extends BasicActivity {
	@ViewInject(R.id.home_title)
	public View home_title;
	@ViewInject(R.id.home_title_txt)
	public TextView home_title_txt;
	@ViewInject(R.id.home_right)
	public TextView home_right;
	
	private List<Fragment> mTabContents = new ArrayList<Fragment>();
	private FragmentPagerAdapter mAdapter;
	private List<String> mDatas = Arrays.asList("回款中", "投标中", "已结清", "预约标");
	private List<String> mType = Arrays.asList("paying", "investing", "finished", "order");
	
	@ViewInject(R.id.id_indicator)
	private ViewPagerIndicator mIndicator;
	@ViewInject(R.id.id_vp)
	private ViewPager mViewPager;
	
	private String selection ;
	
//	private final int INVESTMENTCOUNT = 1;
	
	
	public static Intent getIntent(Context context ,String selection) {
		Intent intent = new Intent(context,InvestmentListActivity.class);
		intent.putExtra("selection", selection);

		return intent;
	}
	
	private void initDatas(){
		selection = getIntent().getStringExtra("selection");
		
		for (int i = 0;i<mType.size();i++) {
			InvestmentTypeFragment fragment = InvestmentTypeFragment.newInstance(mType.get(i));

			mTabContents.add(fragment);
		}

		mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
			@Override
			public int getCount() {
				return mTabContents.size();
			}

			@Override
			public Fragment getItem(int position) {
				return mTabContents.get(position);
			}
		};
		
		
		mIndicator.setTabItemTitles(mDatas);
		
		mViewPager.setAdapter(mAdapter);
		
		mIndicator.setViewPager(mViewPager, 0);
		
		if (!TextUtils.isEmpty(selection)&& "1".equals(selection)) {
			mViewPager.setCurrentItem(1);
		}
		
	}

	public void onPostSuccess(int postId, String result) {
		/*Gson gson = new Gson();
		switch (postId) {
		case INVESTMENTCOUNT:
			java.lang.reflect.Type type2 = new TypeToken<InvestmentCount>() {}.getType();
			InvestmentCount investmentCount = gson.fromJson(result, type2);
			
			mDatas = Arrays.asList("回款中("+investmentCount.paying+")", "投标中("+investmentCount.investing+")", "已结清("+investmentCount.finished+")", "预约标");
			
			initDatas();
			
			break;
		default:
			break;
		}*/
	}

	@Override
	protected void setParams() {
		home_title_txt.setText(getString(R.string.assets_investment_list));
		home_title.setOnTouchListener(touch);
		
		initDatas();
	}


	@Override
	protected void leftButton() {
		AppBasic.getInstance().finishCurrentActivity();
	}

	@Override
	protected void rightButton() {
		
	}

	@Override
	public void onPostFailure(int postId, String msg) {
		
	}
	
}
